import Vue from 'vue'
import Router from 'vue-router'
import Index_Main from '@/components/Index_Main'
import Login from '@/components/account/Login'
import Register from '@/components/account/Register'
import FindPassword from '@/components/account/FindPassword'
import Account from '@/components/Account'
import Home from '@/components/Home'
import Forum from '@/components/Forum'
import Release from '@/components/Release'
import Message from '@/components/Message'
import Topic from '@/components/Topic'
import ChangePassword from '@/components/account/ChangePassword'
import PersonInfo from '@/components/account/PersonInfo'
import ForumSection from '@/components/sectionContent/ForumSection'

Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

export default new Router({
  routes: [
    {
      path: '/',
      name: 'Index_Main',
      component: Index_Main,
      redirect: { name: 'home' },
      children: [
        {
          path: 'account',
          name: 'account',
          component: Account,
          meta: { requiresAuth: true }
        },
        {
          path: 'home',
          name: 'home',
          component: Home
        },
        {
          path: 'forum',
          name: 'forum',
          component: Forum,
          props: route => ({
            fsection: route.query.fsection,
            csection: route.query.csection
          }),
          children: [
            {
              path: 'forum',
              name: 'forumsection',
              component: ForumSection
            }
          ]
        },
        {
          path: 'release/:fsection',
          name: 'release',
          component: Release,
          meta: { requiresAuth: true }
        },
        {
          path: 'message',
          name: 'message',
          component: Message,
          meta: { requiresAuth: true }
        }
      ]
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/findpassword',
      name: 'findpassword',
      component: FindPassword
    },
    {
      path: '/changepassword',
      name: 'changepassword',
      component: ChangePassword
    },
    {
      path: '/personinfo',
      name: 'personinfo',
      component: PersonInfo
    },
    {
      path: '/topic',
      name: 'topic',
      component: Topic
    }
  ]
})
